package com.zhuiyun.project.api.appusercancel.service.impl;

import com.zhuiyun.project.api.appusercancel.entity.userRecovery;
import com.zhuiyun.project.api.appusercancel.mapper.AppUserCancelMapper;
import com.zhuiyun.project.api.appusercancel.mapper.UserRecoverMapper;
import com.zhuiyun.project.api.appusercancel.model.userCancelModel;
import com.zhuiyun.project.api.appusercancel.model.userRecoverModel;
import com.zhuiyun.project.api.appusercancel.service.AppUserCancelService;
import com.zhuiyun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author hbx
 * @Date 2023/6/5 17:11
 **/
@Service
public class AppUserCancelServiceImpl implements AppUserCancelService {

    @Autowired
    AppUserCancelMapper appUserCancelMapper;
    @Autowired
    UserRecoverMapper userRecoverMapper;
    /**
     * 注销的账号查询
     * @author 温
     * @date 2023/7/6 16:12
     * @parameter [userName, pageRequest]
     * @return com.zhuiyun.project.util.pageUtil.PageResult
     */
    @Override
    public PageResult userCancelList(String userName, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        List<userCancelModel> userCancellations = appUserCancelMapper.userCancelList(userName, pageRequest);
        return MybatisPageHelper.getPageResult(userCancellations);
    }

    /**
     * 申请恢复注销用户的查询
     * @author 温
     * @date 2023/6/14 15:34
     * @parameter [userName, pageRequest]
     * @return com.zhuiyun.project.util.pageUtil.PageResult
     */
    @Override
    public PageResult cancelList( PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        List<userRecoverModel> userRecoveries = userRecoverMapper.cancelList( pageRequest);
        return MybatisPageHelper.getPageResult(userRecoveries);
    }




    /**
     * 恢复注销用户
     * @author 温
     * @date 2023/6/15 9:09
     * @parameter [id]
     * @return int
     */
    @Override
    public int restoreUpdate(int restoreId) {
        userRecoverMapper.userRecover(restoreId);
        userRecoverMapper.userRecovers(restoreId);
        int i = userRecoverMapper.userRecoverUpdate(restoreId);
        return i;
    }


    /**
     * 前端申请账号找回驳回
     * @author 温
     * @date 2023/7/6 9:36
     * @parameter [userRecovery]
     * @return int
     */
    @Override
    public int recoverReason(userRecovery userRecovery) {
        int i = userRecoverMapper.recoverReason(userRecovery);
        return i;
    }


    /**
     * 前端用户找回注销账号接口
     * @author 温
     * @date 2023/6/28 19:18
     * @parameter [userRecovery]
     * @return int
     */
    @Override
    public int RecoverAdd(Integer restoreId) {
        int i = userRecoverMapper.RecoverAdd(restoreId);
        return i;
    }

    /**
     * 彻底删除注销的用户
     * @author 温
     * @date 2023/7/12 17:22
     * @parameter [cancellationId]
     * @return int
     */
    @Override
    public int CancelDelete(int cancellationId) {
        int i = appUserCancelMapper.CancelDelete(cancellationId);
        int a = appUserCancelMapper.UserDelete(cancellationId);
        return i+a;
    }

}
